package com.aletto.general_store.ui.adapters;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;

import com.aletto.general_store.R;
import com.aletto.general_store.data.entities.WalletAccount;
import com.aletto.general_store.data.model.Address;
import com.aletto.general_store.ui.activities.ProfileActivity;
import com.aletto.general_store.utils.LocalConfigStore;
import com.aletto.general_store.utils.image.GlideApp;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import androidx.annotation.NonNull;

public class WalletAccountAdapter extends BaseQuickAdapter<WalletAccount, BaseViewHolder> {

    public WalletAccountAdapter() {
        super(R.layout.item_wallet_account);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, WalletAccount walletAccount) {
        Context context = getContext();
        WalletAccount wallet = LocalConfigStore.getInstance().getWallet();

        holder.setVisible(R.id.view, wallet.getAddress().equals(walletAccount.getAddress()))
                .setText(R.id.tv_wallet_name, walletAccount.getNickname())
                .setText(R.id.tv_wallet_address, walletAccount.getAddress());

        ImageView ivAvatar = holder.getView(R.id.iv_avatar);
        GlideApp.with(ivAvatar).load(walletAccount.getAvatar()).avatar().into(ivAvatar);

        // 编辑钱包
        holder.getView(R.id.iv_edit_profile).setOnClickListener(v ->
                context.startActivity(ProfileActivity.newIntent(v.getContext(), walletAccount.getAddress())));
    }

}
